<!--
 * @Author: 孙开源 && sunkaiyuan@namenode.cn
 * @Date: 2023-07-19 15:12:45
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @LastEditTime: 2023-08-16 13:25:07
 * @Description: 
 * 
-->
<template>
  <el-dialog  draggable overflow :title="'编辑'" v-model="visible" :width="560" destroy-on-close @closed="$emit('closed')">
    <sk-tabs type="border-card">
      <el-tab-pane ref="tab" label="基础信息">
        <el-form :model="form" :rules="rules" ref="dialogForm" label-width="100px" label-position="right">
          <el-row>
            <el-col :span="24">
              <el-form-item label="工艺编号" prop="code">
                <el-input label="工艺编号" v-model="form.code" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="工艺名称" prop="name">
                <el-input label="工艺名称" v-model="form.name" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="染料" prop="rawIds">
                <skDicCheckBox v-model="form.rawIds" :code="'rawIds'"></skDicCheckBox>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="后处理" prop="craftIds">
                <skDicCheckBox v-model="form.craftIds" :code="'EndCraft'"></skDicCheckBox>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="色系" prop="ColorShadeIds">
                <skDicCheckBox v-model="form.ColorShadeIds" :code="'ColorShade'"></skDicCheckBox>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="产品" prop="materialCategoryIds">
                <skDicCheckBox v-model="form.materialCategoryIds" :code="'materialCategoryIds'"></skDicCheckBox>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="分类" prop="category_id">
                <skDicSelect v-model="form.category_id" :code="'dyecraftCategory'" :placeholder="'请选择分类'">
                </skDicSelect>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="工艺内容" prop="data">
                <el-input type="textarea" v-model="form.data" :rows="6"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-tab-pane>
      <el-tab-pane ref="tab1" label="后处理工艺">
        <sc-VxeTable ref="xGrid1" :tablecode="'pro_dyecraft_end'" :gridEvts="gridEvts" :data="form.details">
        </sc-VxeTable>
      </el-tab-pane>
    </sk-tabs>
    <template #footer>
      <el-button @click="$emit('closed')">取 消</el-button>
      <el-button type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
    </template>
  </el-dialog>
  <skBrowserChoose v-if="openChooseDlg" v-model="openChooseDlg" :name="'dyecraft'" @close="openChooseDlg = false"
    :single="true" :params="{ category_id: 2 }" @select="selectchoose"></skBrowserChoose>
</template>

<script>
import skDicSelect from "@/components/skDicSelect";
import skDicCheckBox from "@/components/skDicCheckBox";
import skBrowserChoose from "@/components/skBrowserChoose";
export default {
  emits: ["success", "closed"],
  components: { skDicCheckBox, skDicSelect, skBrowserChoose },
  data() {
    return {
      openChooseDlg: false,
      mode: "edit",
      form: {
        id: "",
        code: "",
        name: "",
        materialCategoryIds: "",
        ColorShadeIds: "",
        craftIds: "",
        rawIds: "",
        data: "",
        details: []
        // billdate: tool.SYS_DATE()
      },
      rules: {
        // billdate: [{ required: true, message: "请输入型号规格" }],
      },
      visible: false,
      isSaveing: false,
      gridEvts: {
        choose: () => {
          this.openChooseDlg = true
        },
      }
    };
  },
  mounted() { },
  methods: {
    //显示
    open() {
      this.visible = true;
      return this;
    },
    selectchoose(data) {
      delete data.id;
      this.form.details.push(data);
      this.openChooseDlg = false
    },
    //表单提交方法
    submit() {
      this.$refs.dialogForm.validate(async (valid) => {
        if (valid) {
          this.isSaveing = true;

          this.form.materialCategoryIds = (typeof (this.form.materialCategoryIds ?? "") == "string") ? this.form.materialCategoryIds : this.form.materialCategoryIds.join(",");
          this.form.ColorShadeIds = (typeof (this.form.ColorShadeIds ?? "") == "string") ? this.form.ColorShadeIds : this.form.ColorShadeIds.join(",");
          this.form.craftIds = (typeof (this.form.craftIds ?? "") == "string") ? this.form.craftIds : this.form.craftIds.join(",");
          this.form.rawIds = (typeof (this.form.rawIds ?? "") == "string") ? this.form.rawIds : this.form.rawIds.join(",");

          var res = await this.$API.pro.dyecraft.save.post(this.form);
          this.isSaveing = false;
          if (res.code == 200) {
            this.$emit("success", this.form, this.mode);
            this.visible = false;
            this.$message.success("操作成功");
          }
        }
      });
    },
    getDetail(rscode) {
      this.$API.pro.dyecraft.details.get({ code: rscode }).then((res) => {
        this.form.details = res.data;
      });
    },
    //表单注入数据
    setData(data) {
      Object.assign(this.form, data);
      this.getDetail(this.form.code);
    },
  },
};
</script>

<style></style>
